package com.ruoyi.major.controller;

import java.util.List;


import com.ruoyi.common.utils.uuid.IdUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.major.domain.major;
import com.ruoyi.major.service.ImajorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业信息管理Controller
 *
 * @author chenxl
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/major/major")
public class majorController extends BaseController
{
    @Autowired
    private ImajorService majorService;

    /**
     * 查询专业信息管理列表
     */
    //@PreAuthorize("@ss.hasPermi('major:major:list')")
    @GetMapping("/list")
    public TableDataInfo list(major major)
    {
        startPage();
        List<major> list = majorService.selectmajorList(major);
        return getDataTable(list);
    }

    /**
     * 导出专业信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('major:major:export')")
    @Log(title = "专业信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, major major)
    {
        List<major> list = majorService.selectmajorList(major);
        ExcelUtil<major> util = new ExcelUtil<major>(major.class);
        util.exportExcel(response, list, "专业信息管理数据");
    }

    /**
     * 获取专业信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('major:major:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(majorService.selectmajorById(id));
    }

    /**
     * 新增专业信息管理
     */
    @PreAuthorize("@ss.hasPermi('major:major:add')")
    @Log(title = "专业信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody major major)
    {   major.setId(IdUtils.fastSimpleUUID());
        return toAjax(majorService.insertmajor(major));
    }

    /**
     * 修改专业信息管理
     */
    @PreAuthorize("@ss.hasPermi('major:major:edit')")
    @Log(title = "专业信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody major major)
    {
        return toAjax(majorService.updatemajor(major));
    }

    /**
     * 删除专业信息管理
     */
    @PreAuthorize("@ss.hasPermi('major:major:remove')")
    @Log(title = "专业信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(majorService.deletemajorByIds(ids));
    }
    /**
     * 根据学院id查询所有专业
     */
    //@PreAuthorize("@ss.hasPermi('major:major:query')")
    @GetMapping(value = "/listMajorByCollegeId/{collegeId}")
    public TableDataInfo listMajorByCollegeId(@PathVariable("collegeId") String collegeId)
    {
        //转为list类型返回
        //return success(majorService.selectMajorByCollegeId(collegeId));

        List<major> list = majorService.selectMajorByCollegeId(collegeId);
        System.out.print(list);
        return getDataTable(list);
    }

}
